package com.ruoyi.wms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.wms.domain.WmsBorrowDetails;
import com.ruoyi.wms.service.IWmsBorrowDetailsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物料借用单明细Controller
 * 
 * @author ruoyi
 * @date 2021-11-05
 */
@RestController
@RequestMapping("/borrowDetails")
public class WmsBorrowDetailsController extends BaseController
{
    @Autowired
    private IWmsBorrowDetailsService wmsBorrowDetailsService;

    /**
     * 查询物料借用单明细列表
     */
    @PreAuthorize(hasPermi = "wms:borrowDetails:list")
    @GetMapping("/list")
    public TableDataInfo list(WmsBorrowDetails wmsBorrowDetails)
    {
        startPage();
        List<WmsBorrowDetails> list = wmsBorrowDetailsService.selectWmsBorrowDetailsList(wmsBorrowDetails);
        return getDataTable(list);
    }

    /**
     * 导出物料借用单明细列表
     */
    @PreAuthorize(hasPermi = "wms:borrowDetails:export")
    @Log(title = "物料借用单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsBorrowDetails wmsBorrowDetails) throws IOException
    {
        List<WmsBorrowDetails> list = wmsBorrowDetailsService.selectWmsBorrowDetailsList(wmsBorrowDetails);
        ExcelUtil<WmsBorrowDetails> util = new ExcelUtil<WmsBorrowDetails>(WmsBorrowDetails.class);
        util.exportExcel(response, list, "物料借用单明细数据");
    }

    /**
     * 获取物料借用单明细详细信息
     */
    @PreAuthorize(hasPermi = "wms:borrowDetails:query")
    @GetMapping(value = "/{borrowDetailUuid}")
    public AjaxResult getInfo(@PathVariable("borrowDetailUuid") String borrowDetailUuid)
    {
        return AjaxResult.success(wmsBorrowDetailsService.selectWmsBorrowDetailsByBorrowDetailUuid(borrowDetailUuid));
    }

    /**
     * 新增物料借用单明细
     */
    @PreAuthorize(hasPermi = "wms:borrowDetails:add")
    @Log(title = "物料借用单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsBorrowDetails wmsBorrowDetails)
    {
        return toAjax(wmsBorrowDetailsService.insertWmsBorrowDetails(wmsBorrowDetails));
    }

    /**
     * 修改物料借用单明细
     */
    @PreAuthorize(hasPermi = "wms:borrowDetails:edit")
    @Log(title = "物料借用单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsBorrowDetails wmsBorrowDetails)
    {
        return toAjax(wmsBorrowDetailsService.updateWmsBorrowDetails(wmsBorrowDetails));
    }

    /**
     * 删除物料借用单明细
     */
    @PreAuthorize(hasPermi = "wms:borrowDetails:remove")
    @Log(title = "物料借用单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{borrowDetailUuids}")
    public AjaxResult remove(@PathVariable String[] borrowDetailUuids)
    {
        return toAjax(wmsBorrowDetailsService.deleteWmsBorrowDetailsByBorrowDetailUuids(borrowDetailUuids));
    }
}
